package com.cz.run.bumng;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.cz.run.beans.mysql.*;
import com.cz.run.beans.vo.sport.ForceVO;
import com.cz.run.beans.vo.user.ShcVO;
import com.cz.run.bumng.model.*;
import com.cz.run.service.*;
import com.cz.run.utils.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * Created by deior on 2018/6/9.
 */
@Controller
@RequestMapping("/bumng")
public class UserController {
    @Autowired
    private IUserPocketService iUserPocketService;
    @Autowired
    private IDeliveryAddressService iDeliveryAddressService;

    @Autowired
    private IUserBaseService iUserBaseService;

    @Autowired
    private IUserTradeRecordService iUserTradeRecordService;
    @Autowired
    private IUserPocketPointLogService iUserPocketPointLogService;
    @Autowired
    private IUserPointService iUserPointService;
    @Autowired
    private IUserPointService userPointService;
    @Autowired
    private IForceStatisticsService forceStatisticsService;

    @Autowired
    private IUserForceService userForceService;

    @Autowired
    private IPoolService iPoolService;

    @Autowired
    private IUserPointFrozenService iUserPointFrozenService;

    @Autowired
    private IUserReferralService iUserReferralService;

    @Autowired
    private IUserForceCoefficientService userForceCoefficientService;

    @Autowired
    private IUserForceDynamicService iUserForceDynamicService;

    @RequestMapping(value ="/userAddress.htm",method = RequestMethod.GET)
    public String userAddress(HttpServletRequest request, @ModelAttribute BumngUser bumngUser, Model model){


        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);

        String phone = request.getParameter("phone");
        model.addAttribute("phone",phone);

        PageModel pageModel =  PageUtil.getPageData(request);

        List<AddressModel> addressModels = new ArrayList<>();

        BeanCopier bc = BeanCopier.create(DeliveryAddress.class,AddressModel.class,false);

        EntityWrapper<DeliveryAddress> ew = new EntityWrapper<>();
        ew.where("1 = 1").and(StringUtils.hasLength(phone),"phone = {0}",phone)
                .orderBy("create_time desc limit "+pageModel.getPageNum()+","+pageModel.getPageSize());
        List<DeliveryAddress> addressList =  iDeliveryAddressService.selectList(ew);

        for(DeliveryAddress address:addressList) {
            AddressModel addressModel =new AddressModel();
            bc.copy(address,addressModel,null);
            EntityWrapper<UserBase> uew = new EntityWrapper<>();
            uew.where("id={0}",address.getUserId());
            UserBase userBase = iUserBaseService.selectOne(uew);
            addressModel.setUserName(null==userBase?"":userBase.getRealName());
            addressModels.add(addressModel);
        }
        model.addAttribute("addressList",addressModels);

        EntityWrapper<DeliveryAddress> ew1 = new EntityWrapper<>();
        ew1.where("1 = 1").and(StringUtils.hasLength(phone),"phone = {0}",phone)
             ;
       int count =  iDeliveryAddressService.selectCount(ew1);

        model.addAttribute("pageTotal",count%pageModel.getPageSize()>0?count/10+1:count/10);
        model.addAttribute("pageNum",(pageModel.getPageNum())/10+1);

        return "userAddress";
    }


    @RequestMapping(value ="/userTrade.htm",method = RequestMethod.GET)
    public String userTrade(HttpServletRequest request, @ModelAttribute BumngUser bumngUser, Model model){

        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);

        String address = request.getParameter("address");
        String userName = request.getParameter("userName");

        model.addAttribute("address",address);
        model.addAttribute("userName",userName);

        List<UserTradeMdoel> userTradeMdoels = new ArrayList<>();

        PageModel pageModel =  PageUtil.getPageData(request);

        BeanCopier bc = BeanCopier.create(UserTradeRecord.class,UserTradeMdoel.class,false);

        EntityWrapper<UserTradeRecord> ew = new EntityWrapper<>();
        ew.where("1 = 1").and(StringUtils.hasLength(address),"a.address = {0}",address).and(
                StringUtils.hasLength(userName)," b.real_name = {0}",userName)
                .orderBy("b.create_time desc limit "+pageModel.getPageNum()+","+pageModel.getPageSize());

        List<UserTradeRecord> userTradeRecords =  iUserTradeRecordService.getUserTradeRecordByUserNameAndAddress(ew);

        for(UserTradeRecord userTradeRecord:userTradeRecords) {
            UserTradeMdoel userTradeMdoel =new UserTradeMdoel();
            bc.copy(userTradeRecord,userTradeMdoel,null);
            EntityWrapper<UserBase> uew = new EntityWrapper<>();
            uew.where("id={0}",userTradeRecord.getUserId());
            UserBase userBase = iUserBaseService.selectOne(uew);
            userTradeMdoel.setUserName(null==userBase?"":userBase.getRealName());
            userTradeMdoels.add(userTradeMdoel);
        }


        EntityWrapper<UserTradeRecord> ew1 = new EntityWrapper<>();
        ew1.where("1 = 1").and(StringUtils.hasLength(address),"a.address = {0}",address).and(
                StringUtils.hasLength(userName)," b.real_name = {0}",userName)
                ;

        int count =  iUserTradeRecordService.getCountByUserNameAndAddress(ew1);

        model.addAttribute("pageTotal",count%pageModel.getPageSize()>0?count/10+1:count/10);
        model.addAttribute("pageNum",(pageModel.getPageNum())/10+1);

        model.addAttribute("userTradeMdoels",userTradeMdoels);

        return "userTrade";
    }

    @RequestMapping(value ="/pointList.htm",method = RequestMethod.GET)
    public String pointList(HttpServletRequest request, @ModelAttribute BumngUser bumngUser, Model model){

        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);

        String userName = request.getParameter("userName");
        String phone = request.getParameter("phone");
        String type = request.getParameter("typeSelect");

        model.addAttribute("userName",userName);
        model.addAttribute("phone",phone);
        model.addAttribute("typeSelect",type);

        String sql = "b.create_time desc limit ";

        if(StringUtils.hasLength(type)){
          if("0".equals(type)){
              sql = "a.point desc limit ";
          }else if("1".equals(type)){
              sql = "a.point  limit ";
          }
        }

        PageModel pageModel =  PageUtil.getPageData(request);

        List<UserPointModel> userPointModels = new ArrayList<>();

        BeanCopier bc = BeanCopier.create(UserPoint.class,UserPointModel.class,false);

        EntityWrapper<UserPoint> ew = new EntityWrapper<>();
        ew.where("1 = 1").and(StringUtils.hasLength(userName)," b.real_name = {0}",userName).and(StringUtils.hasLength(phone),"b.phone={0}",phone).
                orderBy(sql+pageModel.getPageNum()+","+pageModel.getPageSize());

        List<UserPoint> userPoints =  iUserPointService.getUserPointByUserName(ew);

        EntityWrapper<UserPoint> ew1 = new EntityWrapper<>();
        ew1.where(
                StringUtils.hasLength(userName)," b.real_name = {0}",userName).and(StringUtils.hasLength(phone),"b.phone={0}",phone);

        int count = iUserPointService.getCountByUserName(ew1);
        model.addAttribute("pageTotal",count%pageModel.getPageSize()>0?count/10+1:count/10);
        model.addAttribute("pageNum",(pageModel.getPageNum())/10+1);
        for(UserPoint userPoint:userPoints) {
            UserPointModel userPointModel =new UserPointModel();
            bc.copy(userPoint,userPointModel,null);
            EntityWrapper<UserBase> uew = new EntityWrapper<>();
            uew.where("id={0}",userPoint.getUserId());
            UserBase userBase = iUserBaseService.selectOne(uew);
            userPointModel.setUserName(null==userBase?"":userBase.getRealName());
            userPointModel.setPhone(null==userBase?"":userBase.getPhone());
            userPointModels.add(userPointModel);
        }
        model.addAttribute("userPointModels",userPointModels);

        EntityWrapper<Pool> ew2 = new EntityWrapper<>();
        ew2.where("1=1 ").orderBy("time desc limit 1");
        Pool pool =iPoolService.selectOne(ew2);
        model.addAttribute("pool",pool);

        return "pointList";
    }



    @RequestMapping(value = "updatePoint.do", method = RequestMethod.POST)
    @ResponseBody
    public Object updatePoint(HttpServletRequest request,  Model model) {


        String point =request.getParameter("point");
        String froceTime =request.getParameter("froceTime");
        if(StringUtils.isEmpty(froceTime)){
            return  new Result(false,"冻结时间不能为空");
        }
        String type =request.getParameter("type");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date time = null;
        if("1".equals(type)) {

            try {
                time = format.parse(froceTime);
            } catch (ParseException e) {
                e.printStackTrace();
                return  new Result(false,"冻结时间格式转化异常");
            }
        }

        EntityWrapper<Pool> pew = new EntityWrapper<>();
        pew.where("time = {0}", DateUtil.currentTimeMillisCN3(new Date()));
        Pool pool = iPoolService.selectOne(pew);

        if(null!=pool){
            pool.setCurrency(Double.parseDouble(point));
            pool.setType(Integer.parseInt(type));
            pool.setTimeFrozen(time);
            iPoolService.update(pool,pew);
        }else{
             pool = new Pool();
            pool.setCurrency(Double.parseDouble(point));
            pool.setTime(new Date());
            pool.setType(Integer.parseInt(type));
            pool.setTimeFrozen(time);
            iPoolService.insert(pool);
        }

        return  new Result(true,"成功");
    }

    @RequestMapping(value = "editPoint.htm")
    public String editNews(HttpServletRequest request, Model model) {
        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);
        String userId =request.getParameter("userId");

       UserBase userBase = iUserBaseService.selectById(Long.parseLong(userId));

        model.addAttribute("userBase",userBase);

        return "editPoint";
    }


    @RequestMapping(value = "addPoint.do", method = RequestMethod.POST)
    @ResponseBody
    public Object addNews(HttpServletRequest request,  Model model) {

        String userId = request.getParameter("id");
        String point = request.getParameter("point");
        String type = request.getParameter("type");
        String froceTime = request.getParameter("froceTime");


        if(StringUtils.isEmpty(point)||StringUtils.isEmpty(userId)){

            return  new Result(false,"参数不能为空");
        }

        if("1".equals(type)&&StringUtils.isEmpty(froceTime)){
            return  new Result(false,"冻结时间不能为空");
        }
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date time = null;

        EntityWrapper<UserPoint> ew = new EntityWrapper<>();
        ew.where("user_id={0}",userId);
        UserPoint userPoint = iUserPointService.selectOne(ew);

        if(null==userPoint){
            return  new Result(false,"用户账户不存在");
        }

        if("1".equals(type)) {

            try {
                time = format.parse(froceTime);
                userPoint.setPointFrozen((null==userPoint.getPointFrozen()?0:userPoint.getPointFrozen())+Double.parseDouble(point));
               iUserPointService.updateById(userPoint);

                UserPointFrozen userPointFrozen = new UserPointFrozen();
                userPointFrozen.setFrom("系统赠送");
                userPointFrozen.setPoint(Double.parseDouble(point));
                userPointFrozen.setStatus(0);
                userPointFrozen.setTime(time);
                userPointFrozen.setUserId(userPoint.getUserId());
                iUserPointFrozenService.insert(userPointFrozen);

            } catch (ParseException e) {
                e.printStackTrace();
                return  new Result(false,"冻结的时间格式转化异常");
            }
        }else {
            userPoint.setPoint((null==userPoint.getPoint()?0:userPoint.getPoint())+Double.parseDouble(point));
            iUserPointService.updateById(userPoint);
        }

        return  new Result(true,"成功");
    }


    @RequestMapping(value = "fh.do", method = RequestMethod.POST)
    @ResponseBody
    public Object fh(HttpServletRequest request,  Model model) {

        String userId = request.getParameter("id");



        if(StringUtils.isEmpty(userId)||StringUtils.isEmpty(userId)){

            return  new Result(false,"参数不能为空");
        }

        EntityWrapper<UserBase> ew = new EntityWrapper<>();
        ew.where("id = {0}",userId);
        UserBase userBase = iUserBaseService.selectOne(ew);

        if(userBase.getStatus()==0){
            userBase.setStatus(1);
        }else{
            userBase.setStatus(0);
        }

        iUserBaseService.updateById(userBase);

        return  new Result(true,"成功");
    }
    @RequestMapping(value = "random.do", method = RequestMethod.POST)
    @ResponseBody
    public Object random(HttpServletRequest request,  Model model) {

        String num = request.getParameter("num");

        if(StringUtils.isEmpty(num)){
            num = "0";
        }

        for(int i =0;i<Integer.parseInt(num);i++){
            try {
                UserBase userBase = new UserBase();
                userBase.setNickName(RandomValue.getChineseName());
                userBase.setPassword(MD5.GetMD5Code("123456"));
                userBase.setPhone(RandomValue.getTel());
                userBase.setUserName(RandomValue.getChineseName());
                iUserBaseService.insert(userBase);

                UserReferral userReferral = new UserReferral();
                userReferral.setUserId(userBase.getId());
                userReferral.setCode(ShareCodeUtil.toSerialCode(userBase.getId()));
                iUserReferralService.insert(userReferral);

                UserForceCoefficient userForceCoefficient = new UserForceCoefficient();
                userForceCoefficient.setUserId(userBase.getId());
                userForceCoefficient.setAddForce(Math.random()*10);
                userForceCoefficient.setBaseForce(Math.random()*100);
                userForceCoefficientService.insert(userForceCoefficient);

                UserForce userForce = new UserForce();
                userForce.setUserId(userBase.getId());
                userForce.setForce(Math.random()*100);
                userForce.setLevel("雏鸡");
                userForceService.insert(userForce);

                UserPoint userPoint = new UserPoint();
                userPoint.setUserId(userBase.getId());
                userPoint.setPoint(Math.random()*1000);
                userPointService.insert(userPoint);

                UserPocket userPocket = new UserPocket();
                userPocket.setUserId(userBase.getId());
                userPocket.setPassword(MD5.GetMD5Code("123456"));
                userPocket.setAddress(genRandomNum());
                userPocket.setCreateTime(new Date());
                userPocket.setUpdateTime(new Date());
                userPocket.setShc(Math.random()*1000);

                iUserPocketService.insert(userPocket);


            }catch (Exception e){

            }
        }



        return  new Result(true,"成功");
    }
    public static String genRandomNum(){
        int  maxNum = 36;
        int i;
        int count = 0;
        char[] str = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
                'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
                'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while(count < 40){
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count ++;
            }
        }
        return "0x" +pwd.toString();
    }


    @RequestMapping(value ="/shcDetail.htm",method = RequestMethod.GET)
    public String shcDetail(HttpServletRequest request, @ModelAttribute BumngUser bumngUser, Model model){

        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);

        EntityWrapper<ForceStatistics> ew = new EntityWrapper<>();
        ew.where("time = {0}", DateUtil.getDateAfterDayYYYYMMDD(new Date(), -1));
        List<ForceStatistics> list = forceStatisticsService.selectList(ew);
        ForceVO avo = new ForceVO();
        if (null != list && list.size() > 0) {
            avo.setAvgForce(list.get(0).getForceAvg());
            avo.setForce(list.get(0).getPoolTotal());
            avo.setMaxForce(list.get(0).getForceMax());
            avo.setMinForce(list.get(0).getForceMin());
            avo.setTotalForce(list.get(0).getForceTotal());
            avo.setYield(list.get(0).getPoolTotal());
            avo.setMaxGetForce(list.get(0).getPointMax());
        }

        String phone = request.getParameter("phone");
        model.addAttribute("phone",phone);

        PageModel pageModel =  PageUtil.getPageData(request);

        EntityWrapper<UserBase> uew = new EntityWrapper<>();
        uew.where("1 = 1").and(StringUtils.hasLength(phone),"phone = {0}",phone).
                orderBy("create_time desc limit "+pageModel.getPageNum()+","+pageModel.getPageSize());
        List<UserBase> userList =  iUserBaseService.selectList(uew);

        EntityWrapper<UserBase> ew1 = new EntityWrapper<>();
        ew1.where(StringUtils.hasLength(phone),"phone = {0}",phone);
        int count =  iUserBaseService.selectCount(ew1);
        List<ShcMdoel> shcVOlist = new ArrayList<>();
        for(UserBase userBase:userList){
            ShcMdoel vo = new ShcMdoel();
            vo.setId(userBase.getId());
            EntityWrapper<UserForce> few = new EntityWrapper<>();
            few.where("user_id = {0}", userBase.getId());
            UserForce userForce = userForceService.selectOne(few);
            if (null != userForce) {
                vo.setMyShc(userForce.getForce());
            }
            EntityWrapper<UserPoint> pew = new EntityWrapper<>();
            pew.where("user_id = {0}", userBase.getId());
            UserPoint point = userPointService.selectOne(pew);
            if (null != point) {
                vo.setShc(point.getPoint());
            }

            EntityWrapper<UserForceCoefficient> coew = new EntityWrapper<>();
            coew.where("user_id = {0}", userBase.getId());
            UserForceCoefficient userForceCoefficient = userForceCoefficientService.selectOne(coew);
            if(null!=userForceCoefficient){
                vo.setAddForce(userForceCoefficient.getAddForce());
                vo.setBase(userForceCoefficient.getBaseForce());
            }

            EntityWrapper<UserForceDynamic> doew = new EntityWrapper<>();
            doew.where("user_id = {0}", userBase.getId());
            doew.and("time = {0}", DateUtil.getDateAfterDayYYYYMMDD(new Date(), 0));
            UserForceDynamic userForceDynamic = iUserForceDynamicService.selectOne(doew);
            if(null!=userForceDynamic){
                vo.setStepNum(userForceDynamic.getStep());
                vo.setTemp(userForceDynamic.getTemp());
            }

            vo.setPhone(userBase.getPhone());


            shcVOlist.add(vo);
        }

        model.addAttribute("shcVOlist",shcVOlist);
        model.addAttribute("avo",avo);
        model.addAttribute("pageTotal",count%pageModel.getPageSize()>0?count/10+1:count/10);
        model.addAttribute("pageNum",(pageModel.getPageNum())/10+1);

        return "shcDetail";
    }
    @RequestMapping(value = "editShc.htm")
    public String editShc(HttpServletRequest request, Model model) {
        BumngUser bumngUser1 = (BumngUser) request.getSession().getAttribute("bumngUser");

        if(null==bumngUser1){
            return "login";
        }
        model.addAttribute("bumngUser",bumngUser1);
        String userIdStr =request.getParameter("userId");
        int userId = 0;
        if(StringUtils.hasLength(userIdStr)){
            userId = Integer.parseInt(userIdStr);
        }
        ShcMdoel vo = new ShcMdoel();


        EntityWrapper<UserBase> uew = new EntityWrapper<>();
        uew.where("id={0}",userId);
        UserBase user =  iUserBaseService.selectOne(uew);

        vo.setId(userId);
        EntityWrapper<UserForce> few = new EntityWrapper<>();
        few.where("user_id = {0}", userId);
        UserForce userForce = userForceService.selectOne(few);
        if (null != userForce) {
            vo.setMyShc(userForce.getForce());
        }
        EntityWrapper<UserPoint> pew = new EntityWrapper<>();
        pew.where("user_id = {0}", userId);
        UserPoint point = userPointService.selectOne(pew);
        if (null != point) {
            vo.setShc(point.getPoint());
        }

        EntityWrapper<UserForceCoefficient> coew = new EntityWrapper<>();
        coew.where("user_id = {0}", userId);
        UserForceCoefficient userForceCoefficient = userForceCoefficientService.selectOne(coew);
        if(null!=userForceCoefficient){
            vo.setAddForce(userForceCoefficient.getAddForce());
            vo.setBase(userForceCoefficient.getBaseForce());
        }

        EntityWrapper<UserForceDynamic> doew = new EntityWrapper<>();
        doew.where("user_id = {0}", userId);
        doew.and("time = {0}", DateUtil.getDateAfterDayYYYYMMDD(new Date(), 0));
        UserForceDynamic userForceDynamic = iUserForceDynamicService.selectOne(doew);
        if(null!=userForceDynamic){
            vo.setStepNum(userForceDynamic.getStep());
            vo.setTemp(userForceDynamic.getTemp());
        }

        vo.setPhone(user.getPhone());

        model.addAttribute("vo",vo);

        return "editShc";
    }

    @RequestMapping(value = "editShc.do", method = RequestMethod.POST)
    @ResponseBody
    public Object editShwc(HttpServletRequest request,  Model model) {

        String userId = request.getParameter("id");
        String myShc = request.getParameter("myShc");
        String stepNum = request.getParameter("stepNum");
        String phone = request.getParameter("phone");
        String temp = request.getParameter("temp");
        String base = request.getParameter("base");
        String addForce = request.getParameter("addForce");

        if(StringUtils.isEmpty(userId)||StringUtils.isEmpty(myShc)||StringUtils.isEmpty(stepNum)
                ||StringUtils.isEmpty(phone)||StringUtils.isEmpty(temp)
                ||StringUtils.isEmpty(base)||StringUtils.isEmpty(addForce)){

            return  new Result(false,"参数不能为空");
        }


        EntityWrapper<UserForce> few = new EntityWrapper<>();
        few.where("user_id = {0}", userId);
        UserForce userForce = new UserForce();
        userForce.setForce(Double.parseDouble(myShc));
        userForce.setUserId(Integer.parseInt(userId));

        if(null==userForceService.selectOne(few)){
            userForceService.insert(userForce);
        }else{
            userForceService.update(userForce,few);
        }

        EntityWrapper<UserForceCoefficient> coew = new EntityWrapper<>();
        coew.where("user_id = {0}", userId);
        UserForceCoefficient userForceCoefficient = new UserForceCoefficient();
        userForceCoefficient.setBaseForce(Double.parseDouble(base));
        userForceCoefficient.setAddForce(Double.parseDouble(addForce));
        userForceCoefficient.setUserId(Integer.parseInt(userId));

        if(null==userForceCoefficientService.selectOne(coew)){
            userForceCoefficientService.insert(userForceCoefficient);
        }else{
            userForceCoefficientService.update(userForceCoefficient,coew);
        }

        EntityWrapper<UserForceDynamic> doew = new EntityWrapper<>();
        doew.where("user_id = {0}", userId);
        doew.and("time = {0}", DateUtil.getDateAfterDayYYYYMMDD(new Date(), 0));
        UserForceDynamic userForceDynamic = new UserForceDynamic();
        userForceDynamic.setStep(Integer.parseInt(stepNum));
        userForceDynamic.setTemp(Double.parseDouble(temp));
        userForceDynamic.setTime(new Date());
        userForceDynamic.setUserId(Integer.parseInt(userId));

        if(null==iUserForceDynamicService.selectOne(doew)){
            iUserForceDynamicService.insert(userForceDynamic);
        }else{
            iUserForceDynamicService.update(userForceDynamic,doew);
        }

        return  new Result(true,"成功");
    }
}
